package com.itheima.service.impl;

import com.itheima.entity.TbBusinessTrackRecord;
import com.itheima.dao.TbBusinessTrackRecordDao;
import com.itheima.service.TbBusinessTrackRecordService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 商机跟进记录(TbBusinessTrackRecord)表服务实现类
 *
 * @author makejava
 * @since 2022-01-16 15:48:53
 */
@Service("tbBusinessTrackRecordService")
public class TbBusinessTrackRecordServiceImpl implements TbBusinessTrackRecordService {
    @Resource
    private TbBusinessTrackRecordDao tbBusinessTrackRecordDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TbBusinessTrackRecord queryById(Long id) {
        return this.tbBusinessTrackRecordDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param tbBusinessTrackRecord 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<TbBusinessTrackRecord> queryByPage(TbBusinessTrackRecord tbBusinessTrackRecord, PageRequest pageRequest) {
        long total = this.tbBusinessTrackRecordDao.count(tbBusinessTrackRecord);
        return new PageImpl<>(this.tbBusinessTrackRecordDao.queryAllByLimit(tbBusinessTrackRecord, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param tbBusinessTrackRecord 实例对象
     * @return 实例对象
     */
    @Override
    public TbBusinessTrackRecord insert(TbBusinessTrackRecord tbBusinessTrackRecord) {
        this.tbBusinessTrackRecordDao.insert(tbBusinessTrackRecord);
        return tbBusinessTrackRecord;
    }

    /**
     * 修改数据
     *
     * @param tbBusinessTrackRecord 实例对象
     * @return 实例对象
     */
    @Override
    public TbBusinessTrackRecord update(TbBusinessTrackRecord tbBusinessTrackRecord) {
        this.tbBusinessTrackRecordDao.update(tbBusinessTrackRecord);
        return this.queryById(tbBusinessTrackRecord.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.tbBusinessTrackRecordDao.deleteById(id) > 0;
    }
}
